package com.lovo;

import com.lovo.hb.dao.IStudentDao;
import com.lovo.hb.dao.ITeacherDao;
import com.lovo.hb.entity.StudentEntity;
import com.lovo.hb.entity.TeacherEntity;
import lombok.extern.log4j.Log4j2;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest(classes = com.lovo.HibernateMain.class)
public class ManyToOne {
    @Autowired
    private ITeacherDao teacherDao;
    @Autowired
    private IStudentDao studentDao;
    @Test
    public void sava(){
     //保存教师
        TeacherEntity t=new TeacherEntity();
        t.setTeacherName("陈老师");
       t= teacherDao.save(t);
        //保存学生
        for(int i=0;i<20;i++){
            StudentEntity s=new StudentEntity();
            s.setStuName("赵云"+i);
            s.setInfo("赵云信息"+i);
            s.setTeacher(t);
            studentDao.save(s);
        }
    }

    @Test
    public void findMany(){
    StudentEntity stu=   studentDao.findById(13l).get();
        System.out.println(stu.getStuName()+stu.getTeacher().getTeacherName());
    }
    @Test
    public void findManyHql(){
  List<StudentEntity> list=   studentDao.findAllByTeacherName("陈老师");
        System.out.println(list);
    }
}
